package com.cxria.pattern.commandAndResponsibilityChain

class CommandVO {

    final static String DIVIDE_FLAG = ' '

    final static String PREFIX = '-'

    private String commandName = ''

    private def paramList = []

    private def dataList = []

    CommandVO(String commandStr) {
        if(commandStr && commandStr.length() != 0){
            String[] complexStr = commandStr.split(DIVIDE_FLAG)
            commandName = complexStr[0]
            for(int i = 1; i<complexStr.length; i++){
                String str = complexStr[i]
                if(str.indexOf(CommandVO.PREFIX) == 0){
                    paramList.add(str.replace(PREFIX, '').trim())
                } else {
                    println '命令解析失败,必须传递一个命令才能执行!'
                }
            }
        }

    }

    List<String> getParam() {
        if(paramList.size() == 0){
            paramList.add('')
        }
        new ArrayList<String>(new HashSet<String>(paramList))
    }

    String getCommandName(){
        commandName
    }

    List<String> getData(){
        dataList
    }

}
